1
|
|
|
import { BaseEndpoint, QueryParameters } from './baseEndpoint'; |
2
|
|
|
import { |
3
|
|
|
TVEpisodeDetailsResponse, |
4
|
|
|
TVEpisodeCreditsResponse, |
5
|
|
|
TVEpisodeExternalIDResponse, |
6
|
|
|
TVEpisodeImagesResponse, |
7
|
|
|
TVEpisodeTranslationsResponse, |
8
|
|
|
TVEpisodeVideosResponse, |
9
|
|
|
} from '../interfaces/tvEpisode'; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* TVEpisode Endpoint Class |
13
|
|
|
*/ |
14
|
|
|
export class TVEpisode extends BaseEndpoint { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Show ID we are working with |
18
|
|
|
* @var number | null |
19
|
|
|
*/ |
20
|
|
|
private showID: number | null = null; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Season Number we are working with |
24
|
|
|
* @var number | null |
25
|
|
|
*/ |
26
|
|
|
private seasonNumber: number | null = null; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Set the Show ID we are working with |
30
|
|
|
* @param { number } showID |
31
|
|
|
* @return TVEpisode |
32
|
|
|
*/ |
33
|
|
|
public show(showID: number): TVEpisode { |
34
|
|
|
this.showID = showID; |
35
|
|
|
return this; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Set the Season Number we are working with |
40
|
|
|
* @param { number } seasonNumber |
41
|
|
|
* @return TVEpisode |
42
|
|
|
*/ |
43
|
|
|
public season(seasonNumber: number): TVEpisode { |
44
|
|
|
this.seasonNumber = seasonNumber; |
45
|
|
|
return this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the TV episode details by id. |
50
|
|
|
* @param { number } episodeNumber |
51
|
|
|
* @param { string[] } appendToResponse |
52
|
|
|
* @return { Promise<TVEpisodeDetailsResponse> } |
53
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-details |
54
|
|
|
*/ |
55
|
|
|
public async details(episodeNumber: number, appendToResponse: string[] = []): Promise<TVEpisodeDetailsResponse> { |
56
|
|
|
this.performChecks(); |
57
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}`, { |
58
|
|
|
append_to_response: appendToResponse, |
59
|
|
|
} as QueryParameters); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Get the credits (cast, crew and guest stars) for a TV episode. |
64
|
|
|
* @param { number } episodeNumber |
65
|
|
|
* @return { Promise<TVEpisodeCreditsResponse> } |
66
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-credits |
67
|
|
|
*/ |
68
|
|
|
public async credits(episodeNumber: number): Promise<TVEpisodeCreditsResponse> { |
69
|
|
|
this.performChecks(); |
70
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}/credits`); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Get the external ids for a TV episode. |
75
|
|
|
* @param { number } episodeNumber |
76
|
|
|
* @return { Promise<TVEpisodeExternalIDResponse> } |
77
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-external-ids |
78
|
|
|
*/ |
79
|
|
|
public async externalIDs(episodeNumber: number): Promise<TVEpisodeExternalIDResponse> { |
80
|
|
|
this.performChecks(); |
81
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}/external_ids`); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get the images that belong to a TV episode. |
86
|
|
|
* @param { number } episodeNumber |
87
|
|
|
* @return { Promise<TVEpisodeImagesResponse> } |
88
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-images |
89
|
|
|
*/ |
90
|
|
|
public async images(episodeNumber: number): Promise<TVEpisodeImagesResponse> { |
91
|
|
|
this.performChecks(); |
92
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}/images`); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Get the translation data for an episode. |
97
|
|
|
* @param { number } episodeNumber |
98
|
|
|
* @return { Promise<TVEpisodeTranslationsResponse> } |
99
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-translations |
100
|
|
|
*/ |
101
|
|
|
public async translations(episodeNumber: number): Promise<TVEpisodeTranslationsResponse> { |
102
|
|
|
this.performChecks(); |
103
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}/translations`); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get the videos that have been added to a TV episode. |
108
|
|
|
* @param { number } episodeNumber |
109
|
|
|
* @return { Promise<TVEpisodeVideosResponse> } |
110
|
|
|
* @see https://developers.themoviedb.org/3/tv-episodes/get-tv-episode-videos |
111
|
|
|
*/ |
112
|
|
|
public async videos(episodeNumber: number): Promise<TVEpisodeVideosResponse> { |
113
|
|
|
this.performChecks(); |
114
|
|
|
return this.sendGetRequest(`tv/${this.showID}/season/${this.seasonNumber}/episode/${episodeNumber}/videos`); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Perform necessary checks before executing request |
119
|
|
|
* @return void |
120
|
|
|
*/ |
121
|
|
|
private performChecks(): void { |
122
|
|
|
if (this.showID === null) { |
123
|
|
|
throw new Error('You must set the Show ID first via the `show(showID: number)` method!'); |
124
|
|
|
} |
125
|
|
|
if (this.seasonNumber === null) { |
126
|
|
|
throw new Error('You must set the Season Number first via the `season(seasonNumber: number)` method!'); |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
} |
131
|
|
|
|